package com.ny.dao.impl;

import com.ny.dao.ManagerDao;
import com.ny.entity.Manager;
import com.ny.until.SqlConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ManagerDaoImpl implements ManagerDao {
    Connection connection = SqlConnection.getCon();

    public ManagerDaoImpl() throws SQLException {
    }


    public Manager login1(String managerName, String managerPassword) throws SQLException {
        String sql = "select * from managers where name = ? and password = ?";
//         3.执行SQL语句
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        // 给问号赋值
        preparedStatement.setString(1,managerName);
        preparedStatement.setString(2,managerPassword);
        ResultSet resultSet = preparedStatement.executeQuery();
//
        if (resultSet.next()){
            Manager manager = new Manager();
            manager.setManagerId(resultSet.getInt("manager_id"));
            manager.setManagerName(resultSet.getString("name"));
            manager.setManagerPassword(resultSet.getString("password"));
            return manager;
        }
        return null;
    }




}
